import { Component,Input,NgModule } from '@angular/core';
import {FormsModule} from '@angular/forms';
import {Router,ActivatedRoute} from '@angular/router'
import axios from 'axios';
import { environment } from '@/environment/environment';
import { prompt } from '@/globals';

@Component({
  selector: 'app-login',
  standalone: true,
  imports: [FormsModule],
  templateUrl: './login.component.html',
  styleUrl: './login.component.scss'
})


export class LoginComponent {

  user:  string = 'a';
  password:  string = '123as123';

  constructor(private route: ActivatedRoute, private router: Router){

  }
  
  login(){
    axios({
        method: 'post',
        url: `${environment.apiUrl}/api/users/login`,
        data: {
            user: this.user,
            password: this.password,
        }
    }).then( (response)=> {
        if(response.data.code){
            localStorage.setItem('token',response.data.data.token);
            prompt('登陆成功');
            console.log('ada');
            setTimeout(() => {
              this.router.navigate(['/'], { relativeTo: this.route });
              //router.replace('/')
            }, 2000);
            //
        }else{
        }
    }).catch(function (error) {
        console.log(error);
    });
  }
}
